# for topic 11 b for Binomial distributions # # As an example, if the probability of success is # 0.573 and we have 6 trials and we want 2 successes, # we can get the probability of that via source("../combinations.R") nCr(6,2)*0.573^2*(1-0.573)^4 # # demonstrate the use of pbinom() # For probability of a single success equal to 0.45 # in 6 trials find the probability of getting 3 # or fewer successes. pbinom( 3, 6, 0.45) # Change probability of single success on one trial # to 0.70, in 6 trials, find P(X>=2) 1 - pbinom( 1, 6, 0.70) # For 13 trials with p=0.64 find P(X<=8) pbinom( 8, 13, 0.64 ) # For 13 trials with p=0.41, find P(X<7). # But P(X<7) is the same as P(X<=6) pbinom( 6, 13, 0.41) # For 9 trials with p=0.573, find # P(4 <= X <= 7) pbinom( 7, 9, 0.573 ) - pbinom( 3, 9, 0.573 ) # For 12 trials, p=0.379, find P(X=5). pbinom( 5, 12, 0.379 ) - pbinom( 4, 12, 0.379 ) # alternatively, ... source("../pbinomeq.R") pbinomeq( 5, 12, 0.379) # solve P(X>=11) with 19 trials and p=0.637 # two different ways 1 - pbinom( 10, 19, 0.637 ) # the old way pbinom( 10, 19, 0.637, lower.tail=FALSE) # the new way # # find the mean and standard deviation for a # binomial distribution with 17 trials and p=0.634 mu <- 17*0.634 mu sigma <- sqrt( 17*0.634*(1-0.634)) sigma